<?php
$path = 'instls/mods/' . basename(dirname(__FILE__));
$myPdo = DbUtils::createPdoInst();
$data = DbUtils::get($myPdo, 'pz2_ui', NULL, 't.folder', 'ASC', NULL, NULL, NULL)->d;
?>
<style>
.list {
  border-left: 1px solid #ddd;
  border-top: 1px solid #ddd;
}
.list td {
  vertical-align: middle;
  text-align: left;
  padding: 2px; 
  border-right: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
}
.list td.nosort {
  background-color: #dababa;
  font-weight: bold;
  
}
.list tr.none td {
  background-color: #fff;
}
.list tr.rowodd td {
  background-color: #eee;
}
.list tr.roweven td {
  background-color: #fff;
}
.list tr.rowodd:hover td {
  background-color: #f4f3b2;
}
.list tr.roweven:hover td {
  background-color: #f4f3b2;
}
</style>
<div id="cancelBtnId" style="display: none;"></div>
<div id="spanButtonPlaceHolder"></div>
<table class="list" cellpadding=0 cellspacing=0>
  <tr>
    <td class="nosort" style="width: 250px;">Name</td>
    <td class="nosort" style="width: 20px;"></td>
  </tr>
  <?php foreach ($data as $idx => $obj) { ?>
    <tr class="<?php echo ($idx % 2 == 0) ? 'roweven' : 'rowodd'; ?>">
      <td><?php echo $obj->folder; ?></td>
      <td><img style="cursor: pointer;" src="<?php echo $path; ?>/assets/imgs/delete24.png" onclick="remove('<?php echo $obj->id; ?>', '<?php echo $obj->folder; ?>')"></img></td>
    </tr>
  <?php } ?>
  <?php if (count($data) == 0) { ?>
    <tr class="none"><td colspan=2>None</td></tr>
  <?php } ?>
</table>
<script type="text/javascript" src="libs/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="incls/js/myutils.js"></script>
<script type="text/javascript" src="libs/swfupload/swfupload.js"></script>
<script type="text/javascript" src="libs/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="libs/swfupload/myupload.js"></script>
<script type="text/javascript">
  $(function(){
    var pos = MyUtils.findPos($('#spanButtonPlaceHolder')[0]);
    new MyUpload('spanButtonPlaceHolder', 'instls/exts.php', function(msgs) {
      parent.location.reload();
    }, {
      dir: '',
      button_image_url: '<?php echo $path; ?>/assets/imgs/browse.png',
      button_width: 150,
      button_height: 25,
      file_size_limit: '100MB',
      file_types: '*.zip',
      file_types_description: 'PZ UI',
      cancelBtnId: 'cancelBtnId',
      post_params: {
        action: 'uis'
      },
      debug: 0
    });
  });
  
  function remove(id, folder) {
    var r = window.confirm('Click OK to Proceed?');
    if (r) {
      $.ajax({
        type: 'POST',
        url: '<?php echo $path . '/' . basename(__FILE__, '.php'); ?>.server.php',
        data: 'action=remove&i=' + encodeURIComponent(id) + '&f=' + encodeURIComponent(folder),
        success: function(msg) {
          location.reload();
        }
      });
    }
  }
</script>